/*
 * @lc app=leetcode.cn id=897 lang=cpp
 *
 * [897] 递增顺序搜索树
 */

// @lc code=start
/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution
{
public:
  TreeNode* dummy;
  TreeNode* pre;

  TreeNode* increasingBST(TreeNode* root)
  {
    this->dummy = new TreeNode(-1);
    this->pre = dummy;
    DFS(root);
    return dummy->right;
  }

  void DFS(TreeNode* root)
  {
    if (root) {
      DFS(root->left);
      pre->right = root;
      pre = root;
      DFS(root->right);
      root->left = nullptr;
    }
  }
};
// @lc code=end
